{% extends "base.html" %}

{% block content %}

<style>
	 form {
		margin: 0px;
	}
	
	.bc {
		background-color: #ffffff;
		line-height: 25px;
	}
	
	.bc0 {
		background-color: #ffffff;
		line-height: 25px;
	}
	
	.bc1 {
		background-color: #991100;
		line-height: 25px;
		color: #ffffff
	}
	
	.bc2 {
		background-color: #ffdddd;
		line-height: 25px;
	}
	
	.bc3 {
		background-color: #ffffbb;
		line-height: 25px;
	}
	
	.bc4 {
		background-color: #11cc00;
		line-height: 25px;
	}
	
	.bc5 {
		background-color: #DAEEFE;
		line-height: 25px;
	}
	
	.bcgray {
		background-color: #cccccc;
		line-height: 25px;
		color: #ffffff
	}
	
	.bcblack {
		background-color: #000000;
		line-height: 25px;
		color: #ffffff
	}
	
	td {
		word-wrap: break-word;
	}
	
	.bc1 a:link {
		color: #ffffff
	}
	
	.bc1 a:visited {
		color: #ffffff
	}
	
	.bc4 a:link {
		color: #ffffff
	}
	
	.bc4 a:visited {
		color: #ffffff
	}
	
	.bcgray a:link {
		color: #ffffff
	}
	
	.bcgray a:visited {
		color: #ffffff
	}
	
	.bcblack a:link {
		color: #ffffff
	}
	
	.bcblack a:visited {
		color: #ffffff
	}
	
	#w150 {
		width: 150px;
		overflow: hidden;
		text-overflow: ellipsis;
		*white-space: nowrap;
	}
	
	/*MyTips*/
	#popupcontainer {
		height: auto;
		width: 180px;
		z-index: 100;
	}
	
	#popupcontent {
		text-align: left;
		height: auto;
		width: auto;
		font-family: Arial, Helvetica, sans-serif;
		font-size: 12px;
		color: #0052FF;
		position: relative;
		top: 0px;
		left: 0px;
		padding: 12px 15px 0px 10px;
		border: none;
		background-image: url('/static/images/mytiptop.png');
	}
	
	* html #popupcontent {
		filter: progid : DXImageTransform.Microsoft.AlphaImageLoader ( enabled =
			true, sizingMethod = crop src = '/static/images/mytiptop.png' );
		background-image: none;
		height: 100%;
	}
	
	#popupbottom {
		position: relative;
		width: 180px;
		height: 18px;
		background-image: url('/static/images/mytipbottom.png');
	}
</style>
<script language="javascript" src="/static/js/jquery-1.2.1.pack.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/js/jquery-calendar-pack.js" ></script>
<script type="text/javascript" src="/static/js/urltip.js" ></script>
<script type="text/javascript" src="/static/js/ajax.js" ></script>
<style type="text/css">@import url(/static/css/jquery-calendar.css);</style>
<script language="javascript" type="text/javascript">
$(document).ready(
	function()
	{
    	popUpCal.regional['zh-cn'] = {
		dateFormat: 'YMD-'};
		popUpCal.setDefaults(popUpCal.regional['zh-cn']);
	    $('#start_date').calendar({autoPopUp: 'focus',yearRange: '-10:+0'});
		$('#end_date').calendar({autoPopUp: 'focus',yearRange: '-10:+0'});
		//$("#programt").html($("#p_id [selected]").text());
		
		$('#search').click(function(){
			param = $('#searchForm').serialize();
			
			//var sales = encodeURIComponent($("#sales").val());
			//var name = encodeURIComponent($("#name").val());
			//var tel = encodeURIComponent($("#tel").val());
			//var email = encodeURIComponent($("#email").val());
			//p_id = $("#p_id").val();
			//a_id = $("#a_id").val();
			//start_date=$("#start_date").val();
			//end_date=$("#end_date").val();
			
			var url = "/v2/stusearch/?page=1" + "&" + param;
			window.location=url;
		});
		
		$('#getmail').click(function(){
			var sales = encodeURIComponent($("#sales").val());
			var name = encodeURIComponent($("#name").val());
			var tel = encodeURIComponent($("#tel").val());
			var email = encodeURIComponent($("#email").val());
			p_id = $("#p_id").val();
			a_id = $("#a_id").val();
			f_id = $("#f_id").val();
			inter = $("#sinterlevel").val();
			statu = $("#sstatus1").val();
			start_date=$("#start_date").val();
			end_date=$("#end_date").val();
			last_contact=$("#last_contact").val();
			var url = "/u/mail/" + "?p_id=" + p_id + "&a_id=" + a_id + "&f_id=" + f_id +"&sales=" + sales +"&name=" + name +"&tel=" + tel +"&email=" + email +"&interlevel=" + inter +"&status=" + statu+"&start_date=" + start_date +"&end_date=" + end_date + "&last_contact=" + last_contact;
			//alert(url);
			//window.open(url, "_blank", "top=20");
			window.location=url;
		});
		
		$('#getpost').click(function(){
			var sales = encodeURIComponent($("#sales").val());
			var name = encodeURIComponent($("#name").val());
			var tel = encodeURIComponent($("#tel").val());
			var email = encodeURIComponent($("#email").val());
			p_id = $("#p_id").val();
			a_id = $("#a_id").val();
			f_id = $("#f_id").val();
			inter = $("#sinterlevel").val();
			statu = $("#sstatus1").val();
			start_date=$("#start_date").val();
			end_date=$("#end_date").val();
			last_contact=$("#last_contact").val();
			var url = "/u/post/" + "?p_id=" + p_id + "&a_id=" + a_id + "&f_id=" + f_id +"&sales=" + sales +"&name=" + name +"&tel=" + tel +"&email=" + email +"&interlevel=" + inter +"&status=" + statu+"&start_date=" + start_date +"&end_date=" + end_date + "&last_contact=" + last_contact;
			//alert(url);
			//window.open(url, "_blank", "top=20");
			window.location=url;
		});
});

function changestatus(e,id,cfm,back)
	{
	  if (confirm(cfm))
		{
		$.post("/changestatus/",{id:id,value:$(e).val()},function(data){
		if(data != "ok")
		{
		alert(data);
		$(e).val(back);
		}});
		}
	else
	$(e).val(back);
	}

function changelevel(e,id,cfm,back){
	  if (confirm(cfm)){
	  	  $.post("/changelevel/",{id:id,value:$(e).val()},function(data){
			  if(data == "ok")
				$(e).parent().parent().attr("class","bc"+$(e).val());
			  else{
					alert(data);
					$(e).val(back);
			   }
		  });
	   }
	   else{
		$(e).val(back);
	   }
}
 </script>
	  <p>
		<span class="tab-back" id="mix-tab"><a href="/v2/stusearch/?page=1&p_id=0">{%if p_id == 0 %}<font color='red'><b>ALL</b></font>{%else%}ALL{%endif%}</a></span>
		{%for p in project_list%}
		<span class="tab-back" id="mix-tab"><a href="/v2/stusearch/?page=1&p_id={{p.id}}">{%if p_id == p.id %}<font color='red'><b>{{p.name}}</b></font>{%else%}{{p.name}}{%endif%}</a></span>
		{%endfor%}
      </p>
<div id="addmail"></div>
<div class="form-div">
  <form action="javascript:search()" name="searchForm" id="searchForm">
	    <img src="/static/images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
	    <table  cellspacing="0" cellpadding="3" border="0" width="100%">
	    	<tr>
	    		<td>
	    			Name:
	    			<input type="text" name="name" id="name" value="{{name}}" />
					<input type='hidden' name='p_id' value='{{p_id}}'/>
	    			<input type="button" value="Search" id='search' class="button"/>
				</td>
	    	</tr>
	    </table>
	
	 
		
		<!--&nbsp;&nbsp;<input type="button" value="Mail Address" id='getmail' class="button"/>
		&nbsp;&nbsp;<input type="button" value="Postal Address" id='getpost' class="button"/>-->
 </form>
</div>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
		<table width='98%'  cellspacing='1' align='center' class='grid'><tr><td colspan='8' class='title' align="center">students list(<span style='color:#CC33FF'> {{p_obj.name}}</span>)</td><td colspan='3' align="right"></tr>
			<tr valign='middle' align='left'></tr>
			<tr valign='middle' align='center'>
				  <td class='odd' width='12%'>ID</td>
				  <!--
				  {%ifequal p_id 0%}
				  <td class='even'>Program</td>
				  {%else%}
				 <td class='even' width='8%'>Agent</td>
				  <td class='odd' width='10%'>Referee</td> 
					{%endifequal%}
					-->
					<td class='even'>Program</td>
				  <td class='odd' width='15%'>Name</td>



				
				  <td class='odd' width='10%'>Start Date</td>
				  <td class='even' width='8%'>Module Completed</td>
				  <td class='odd' width='10%'>Next Payment</td> 
				  <td class='even' width='10%'>Sales</td>				
				  <td class='even' width='13%'>Action</td> 
			 </tr>
			  {% for student in students_list %}
			 
			  <tr valign='middle' align='left' {%if student.othercolor%} {%if student.isblack%} class='bcblack'{%else%}{%if student.isgray%}class='bcgray'{%endif%}{%endif%}{%else%}class='bc{{student.interlevel}}'{%endif%}>
			     <td >{{student.student_id}}</td>
				 <td>{{student.program.name}}</td>
				  <!--{%ifequal p_id 0%}
				<td>{{student.program.name}}</td>
				{%else%}
				 <td >{% ifequal level 'administrators' %}<a href="/ulist/agent/{{ student.agent_id}}">{{student.agent.name}}</a>{%else%}{{student.agent.name}}{%endifequal%}</td>
				 <td >{% ifequal level 'administrators' %}<a href="#">{% if student.referee %} {{student.referee.name}}{% endif %}</a>{%else%}{% if student.referee %} {{student.referee.name}}{% endif %}{%endifequal%}</td>
				{%endifequal%}
				-->
			     <td align="center"><a href="/v2/edit_stu/{{ student.id}}" >{%if student.last_name%}{{student.last_name}} , {{student.first_name}}{%else%}{{student.name}}{%endif%}</a></td>
			      
		  
				 <td align="center"><div id="w150">{%if student.start_date%}{{student.start_date|date:'M d,Y'}}{%endif%}</div></td> 
				 <td align="center">{{student.module_completed_num}}</td> 
				 <td align="center">{%if student.fullpay%}Full Paid{%else%}{%if student.nextpayment%}{{student.nextpayment|date:'M d,Y'}}{%endif%}{%endif%}</td> 
				 <td align="center">{% ifequal level 'administrators' %}<a href="/ulist/sales/{{ student.salesperson_id}}">{{student.salesperson.name}}</a>{%else%}{{student.salesperson.name}}{%endifequal%}</td>
			     <td  align='center'><!--old<a href="/v2/edit_stu/{{ student.id}}">--><a href="/v2/edit_student/{{ student.id}}"><img src="/static/images/icon_edit.gif"border="0" alt="edit" title='edit'></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/v2/del_stu/{{ student.id}}" onclick="return confirm('Are you sure to delete it?');"><img src="/static/images/icon_drop.gif" border="0" alt="delete" title='delete'></a>&nbsp;&nbsp;&nbsp;&nbsp;<img src="/static/images/mail.gif" border="0"  onclick="javascript:ajaxaddmail({{student.id}})" style="cursor:hand;" ></td>
			  </tr>
			
			  {% endfor %}
		</table>
		
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		  <tr>
		    <td align="center">
				<table width='98%'  cellspacing='1' align='center'>
					<tr>
						<td width="50%" bgcolor="#ffffff">
						 	<!--<form name='form1' id='form1' action="/u/search/" method='post'>
							<input type="text" name="keyword" value="" />
							<select name="skind">
								<option value="">Search Conditions</option>
								<option value="byname">By Name</option>
								<option value="byagent">By Agent Name</option>
								<option value="bysales">By Sales Name</option>
								<option value="byemail">By Email</option>
							</select>
							<input type='submit' class='button' name='submit'  id='submit' value=' Search ' onclick="ccc(this.form,this)" />
							</form> -->
						</td>
						<td bgcolor="#ffffff" width="50%" align="right">
							<strong>{{ pw.paginator.count }}</strong>&nbsp;Records&nbsp;&nbsp;
						        {% if pw.is_paginated %}
				                    {% ifequal pw.pageNum 1 %}
				                    	First 
				                    {% else %} 
				                    	<a href="{{pageurl}}?{{pw.firstPage.paramStr}}">First</a>
				                    {% endifequal %}&nbsp;&nbsp;
				                    {% if pw.has_previous %}
				                    	<a href="{{pageurl}}?{{pw.prePage.paramStr}}">Prev</a>
				                    {% else %}
				                    	 Prev
				                    {% endif %}&nbsp;&nbsp;
				                    {% if pw.has_next %}
				                    	<a href="{{pageurl}}?{{pw.nextPage.paramStr}}">Next</a>
				                    {% else %}
				                    	Next
				                    {% endif %}&nbsp;&nbsp;
				                    {% ifequal pw.pageNum pw.paginator.num_pages %}
				                    	Last
				                    {% else %}
				                    	<a href="{{pageurl}}?{{pw.lastPage.paramStr}}">Last</a>
				                    {% endifequal %}
				                    &nbsp;&nbsp;
				                    Current:
				                    <select onchange="window.location='{{pageurl}}?'+this.value">
										{% for x in pw.pages %}
											<option value="{{x.paramStr}}" {% ifequal x.pageNum pw.pageNum %} selected="selected" {% endifequal %}>{{x.pageNum}}</option>
										{% endfor %}
					                </select>&nbsp;&nbsp;
				                {% endif %}              
				         </td>
				       </tr>
				   </table>
			   </td>
			</tr>
		</table>
	</td>
	</tr>
</table>
	
{% endblock %}